from resouces import load_script


class my_translator:
    def __init__(self):
        self.commands=load_script()
        #self.commands=[]
        #lines=load_script()

        # is_text=1
        # i=0
        # text_block=""
        # for line in lines:#把多行文本打包
        #     if line[0]=='{' and line[-1]=='}':
        #         is_text=0
        #         self.commands.append("cmd0"+line[1:-1])
        #         if text_block:
        #             self.commands.append("text"+text_block)
        #     else:
        #         is_text=1
        #         text_block+=line
        #已弃用
    def is_command(self,input_cmd):
        # if input_cmd[0:4]=='cmd0':
        #     return True
        # elif input_cmd[0:4]=='text':
        #     return False
        if input_cmd[0]=='{' and input_cmd[-1]=='}':
            return True
        else:
            return False
    def compile_scripts(self):#把挨在一起的指令打包
        self.sorted_commands=[]
        j=0
        command_block = []
        while j < len(self.commands):

            #print(self.commands[j].strip())
            if self.is_command(self.commands[j].strip())==True:
                command_block.append(self.commands[j].strip()[1:-1].split(' '))
            else:
                if command_block:
                    self.sorted_commands.append([0,command_block,self.commands[j].strip()])#0，1后面便于区分是指令文本复合还是纯文本（避免点一下更新建只有cmd更新文字不更新

                else:
                    self.sorted_commands.append([1,[],self.commands[j].strip()])
                command_block=[]
            j+=1


